<template>
	<view class="topic" @click="navigateToDetail(topic)">
		<view class="cover">
			<image :src="topic.cover" mode="aspectFit"/>
		</view>
		<view class="info">
			<view class="question">
				{{topic.question}}
			</view>
			<view class="detail">
				<text>{{topic.difficulty}}</text>
				<text v-if="topic.studyTime">{{formattedStudyTime}}</text>
				<text v-else>{{topic.views}}次学习</text>
			</view>
		</view>
	</view>
</template>

<script>
import {formatTime} from '../../utils';
	export default {
		name:"topic",
		props:{
			topic:{
				type:Object
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			navigateToDetail(topic){
				uni.navigateTo({
					url:`/pages/detail/detail?id=${topic.id}`
				})
			}
		},
		computed:{
			formattedStudyTime(){
				return formatTime(this.topic.studyTime);
			}
		}
	}
</script>

<style lang="scss">
.topic{
	display: flex;
	align-items: center;
	padding:20rpx;
	.cover{
		flex-shrink: 0;
		width:200rpx;
		height:200rpx;
		image{
			width:100%;
			height:100%;
			object-fit: cover;
			border-radius: 20rpx;
		}
	}
	.info{
		flex-grow: 1;
		padding-left:30rpx;
		.question{
			font-size:32rpx;
			font-weight: bold;
			max-height: 2.4em;
			line-height: 1.2em;
			overflow: hidden;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			text-overflow: ellipsis;
			margin-bottom: 16rpx;
		}
		.detail{
			display: flex;
			justify-content: space-between;
			text{
				font-size: 24rpx;
				&.first-child{
					color:gray;
					margin-right:24rpx;
				}
			}
		}
	}
}
</style>